/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.minecraft_clone.terrain;

import org.meanzoft.m3d.resource.ResourceManager;
import org.meanzoft.m3d.scene.Renderable;
import org.meanzoft.m3d.scene.SceneNode;

import static org.lwjgl.opengl.GL11.*;
/**
 *
 * @author Meanz
 */
public class Terrain extends SceneNode implements Renderable {

    int listId;

    public Terrain() {

        /**
         * Poly 4 points
         */
        listId = glGenLists(1);

        glNewList(listId, GL_COMPILE);
        {
            glBegin(GL_QUADS);
            {
                /**
                 * 5x5
                 * x x x x x
                 * x x x x x
                 * x x x x x
                 * x x x x x
                 * x x x x x
                 */
                float[] vecX = new float[6];
                float[] vecY = new float[6];
                float[] vecZ = new float[6];

                float noise = 1f;
                for (int xPos = 0; xPos < 100; xPos++) {
                    for (int zPos = 0; zPos < 100; zPos++) {
                        glNormal3f(0f, 1f, 0f);
                        glTexCoord2f(0f, 0f);
                        glVertex3f(xPos, 0f, zPos);
                        glTexCoord2f(1f, 0f);
                        glVertex3f(xPos + 1, 0f, zPos);
                        glTexCoord2f(1f, 1f);
                        glVertex3f(xPos + 1, 0f, zPos + 1);
                        glTexCoord2f(0f, 1f);
                        glVertex3f(xPos, 0f, zPos + 1);
                    }
                }
            }
            glEnd();
        }
        glEndList();

    }

    public void render() {
        glEnable(GL_TEXTURE_2D);
        ResourceManager.getManager().getTexture("desert").bind();
        glColor3f(1f, 1f, 1f);
        glCallList(listId);
    }
}
